﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using Vowei.Core.Models;
using Vowei.Data.Helpers;

namespace Vowei.Data.Models
{
    public partial class Milestone : IMilestone, ICommentable, IStatus
    {
        public Milestone()
        {
            this.FillDefaultProperties();
        }
        
        IMilestone IMilestone.Parent
        {
            get { return Parent; }
            set { Parent = (Milestone)value; }
        }

        IQueryable<IMilestone> IContainer<IMilestone>.Children
        {
            get { return Children.AsQueryable<IMilestone>(); }
        }

        public void AddChild(IMilestone child)
        {
            if (child.Parent != null)
                child.Parent.RemoveChild(child);

            child.Parent = this;
            Children.Add((Milestone)child);
        }

        public void RemoveChild(IMilestone child)
        {
            child.Parent = null;
            Children.Remove((Milestone)child);
        }

        public void ClearChildren()
        {
            foreach (var child in Children)
                child.Parent = null;

            Children.Clear();
        }

        IQueryable<IComment> ICommentable.Comments
        {
            get { return Comments.AsQueryable<IComment>(); }
        }

        public void AddComment(IComment comment)
        {
            Comments.Add((Comment)comment);
        }

        public void RemoveComment(IComment comment)
        {
            Comments.Remove((Comment)comment);
        }

        public void Close()
        {
            throw new NotImplementedException();
        }

        public void ReActive()
        {
            throw new NotImplementedException();
        }
    }
}
